Ext.define('CDR.view.manager.pbx.PBXFactory', {
	extend: 'Ext.Panel',
	alias : 'widget.pbxfactory',
	title: 'PBX Factory',
	selectedFactoryId : 0,
	selectedFactory: null,
	pbx: null,
	profileCenter : null,
	initComponent: function() {
		var me = this;
		me.callParent();
		
	},
	layout:'anchor',
	dockedItems: [{
		xtype: 'toolbar',
		items: [{
			text: 'New Factory',
			iconCls: 'icon-add',
			handler: function() {
				
			}
		}, '-' ,{
			text: 'Edit Factory',
			iconCls: 'icon-edit',
			handler: function() {
				
			}
		}]
	}], 
	addItem: function(name, description, id){
		var me = this;
		var com = Ext.createWidget('button',{
			obId: id,
			anchor:'100%',
            text    : name,
			scale: 'large',
			margin: '0 0 10px 0',
			enableToggle: true,
			toggleGroup:'serviceprovider_bnt',
			handler: function(){
				me.selectedFactoryId = this.obId;
				me.selectedFactory = this;
				//get list
				if (me.pbx) {
					var store = me.pbx.view.store;
					store.setProxy({
					  type: 'ajax',
					  url : 'list-pbx-view?pbxFactoryId=' + me.selectedFactoryId,
					  reader: {
						  type: 'json',
						  root: 'results'
					  }
					});
					store.load();
				}
			},
			listeners: {
				'render': function() {
					CDR.toolTips.push({
						target: this.el,
						html: description,
						trackMouse: true
					});
				}
			}
		});
		this.add(com);
		return com;
		
	},
	submitOk: function(data) {
		this.addItem(data.name, data.id);
	}
});